<!-- 
<div class="row">
  <button type="button" id="start-btn" class="btn btn-primary disabled">启动比对行情</button>
  <button type="button" id="stop-btn" class="btn btn-danger disabled">停止比对行情</button>
  <button type="button" id="w-btn" class="btn btn-default disabled"></button>
  <button type="button" id="r-btn" class="btn btn-default disabled"></button>
  <p/>
  <div class="panel panel-default">
    <div id="connect-status" class="panel-body"></div>
  </div>
</div>
 -->
<table id="quote-compare-table" class="easyui-datagrid" title="行情比对" style="height:auto"></table>
<div id="compare-toolbar" class="mitake-table-toolbar">
  <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-add',plain:true" onclick="add()">增加</a>
  <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-remove',plain:true" onclick="remove()">删除</a>
  <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-save',plain:true" onclick="save()">保存</a>
  <a href="javascript:void(0)" class="easyui-linkbutton" data-options="iconCls:'icon-undo',plain:true" onclick="reject()">回复</a>
</div>
<script type="text/javascript">
var updateConnectStatus = '';
var pushIndex = -1;
var editIndex = undefined;

$(document).ready(function()
{
	$('#quote-compare-table').datagrid({
		iconCls: 'icon-edit',
		singleSelect: true,
		toolbar: '#compare-toolbar',
		onClickRow: onClickRow,
		fitColumns: false,
		border: false,
		rownumbers: true,
	    nowrap: true,
	    pagination: true,
	    pagePosition: 'bottom', //、'top','bottom'、'both'。
	    pageNumber: 1,
	    pageSize: 20,
	    pageList: [20, 40, 60, 100, 150, 200],
		columns:
		[[
	  		{field:'a',title:'机房',width:100,editor:'text'},
	  		{field:'b',title:'响应',width:100,editor:'text'},
	  		{field:'c',title:'状态',width:100,editor:'text'},
	  		{field:'d',title:'代码',width:100,editor:'text'},
	  		{field:'e',title:'名称',width:100,editor:'text'},
	  		{field:'f',title:'交易时间',width:100,editor:'text'},
	  		{field:'g',title:'市场别',width:100,editor:'text'},
	  		{field:'h',title:'次类别',width:100,editor:'text'},
	  		{field:'i',title:'最新价',width:100,editor:'text'},
	  		{field:'j',title:'最高价',width:100,editor:'text'},
	  		{field:'k',title:'最低价',width:100,editor:'text'},
	  		{field:'l',title:'今开价',width:100,editor:'text'},
	  		{field:'m',title:'昨收价',width:100,editor:'text'},
	  		{field:'n',title:'涨跌比率',width:100,editor:'text'},
	  		{field:'o',title:'总量',width:100,editor:'text'},
	  		{field:'p',title:'当前成交量',width:100,editor:'text'},
	  		{field:'q',title:'换手率',width:100,editor:'text'},
	  		{field:'r',title:'涨停价',width:100,editor:'text'},
	  		{field:'s',title:'跌停价',width:100,editor:'text'},
	  		{field:'t',title:'均价',width:100,editor:'text'},
	  		{field:'u',title:'涨跌',width:100,editor:'text'},
	  		{field:'v',title:'成交金额',width:100,editor:'text'},
	  		{field:'w',title:'量比',width:100,editor:'text'},
	  		{field:'x',title:'买一价',width:100,editor:'text'},
	  		{field:'y',title:'卖一价',width:100,editor:'text'},
	  		{field:'z',title:'外盘量',width:100,editor:'text'},
	  		{field:'a1',title:'内盘量',width:100,editor:'text'},
	  		{field:'b1',title:'总值',width:100,editor:'text'},
	  		{field:'c1',title:'流值',width:100,editor:'text'},
	  		{field:'d1',title:'净资产',width:100,editor:'text'},
	  		{field:'e1',title:'PE(市盈)',width:100,editor:'text'},
	  		{field:'f1',title:'ROE(净资产收益率)',width:100,editor:'text'},
	  		{field:'g1',title:'总股本',width:100,editor:'text'},
	  		{field:'h1',title:'流通股',width:100,editor:'text'},
	  		{field:'i1',title:'五档买价',width:100,editor:'text'},
	  		{field:'j1',title:'五档卖价',width:100,editor:'text'},
	  		{field:'k1',title:'五档买量',width:100,editor:'text'},
	  		{field:'l1',title:'五档卖量',width:100,editor:'text'},
	  		{field:'m1',title:'五档买单量',width:100,editor:'text'},
	  		{field:'n1',title:'五档卖单量',width:100,editor:'text'},
	  		{field:'o1',title:'振幅比率',width:100,editor:'text'},
	  		{field:'p1',title:'收益',width:100,editor:'text'},
	  		{field:'q1',title:'交易明细',width:100,editor:'text'},
	  		{field:'r1',title:'上涨家数',width:100,editor:'text'},
	  		{field:'s1',title:'平盘家数',width:100,editor:'text'},
	  		{field:'t1',title:'下跌家数',width:100,editor:'text'}
	  	]]
	});
	
	getData();
});

function getData()
{
	send('/d', 'event=g&src=' + pushIndex, function callbackComplete(jqXHR, textStatus)
	{}, 
	function callbackError(jqXHR, textStatus, errorThrown)
	{
		$.messager.alert('通知', errorThrown, 'error');
	}, 
	function callbackSuccess(data, textStatus, jqXHR)
	{
		var info = JSON.parse(data);

		if(info.code == '00000')
		{
			if(info.running == 'true')
			{
				if(info.host.length > 0)
				{
					/**
					var s = '';
					
					for(i = 0 ; i < info.host.length ; i++)
					{
						s += '(' +　info.host[i].ip + '_' + (info.host[1].status == '0' ? "连线中" : "<font style=\"color:#990000;\">断线中</font>") + '),';
					}

					s += '数据比对中.....';
					
					$('#w-btn').text('发送报文数量:' + info.w);
					$('#r-btn').text('回应报文数量:' + info.r);
					$('#connect-status').html(s);
					**/
				}
				
				var rowCount = 0;
				
				if(info.push.length > 0)	
				{
					rowCount = info.push.length;
					
					var jd = '';
					jd += '{\"total\":';
					jd += rowCount + ',';
					jd += '\"rows\":[';
					
					for(i = 0 ; i < rowCount ; i++)
					{
						if(i > 0)
						{
							jd += ',';
						}
						
						jd += '{\"a\":\"' + info.push[i].host + '\",';
						jd += '\"b\":\"' + info.push[i].responseTime + '\",';
						jd += '\"c\":\"' + info.push[i].status.v + '\",';
						jd += '\"d\":\"' + info.push[i].id + '\",';
						jd += '\"e\":\"' + info.push[i].name + '\",';
						jd += '\"f\":\"' + info.push[i].datetime.v + '\",';
						jd += '\"g\":\"' + info.push[i].market.v + '\",';
						jd += '\"h\":\"' + info.push[i].subtype.v + '\",';
						jd += '\"i\":\"' + info.push[i].lastPrice.v + '\",';
						jd += '\"j\":\"' + info.push[i].highPrice.v + '\",';
						jd += '\"k\":\"' + info.push[i].lowPrice.v + '\",';
						jd += '\"l\":\"' + info.push[i].openPrice.v + '\",';
						jd += '\"m\":\"' + info.push[i].preClosePrice.v + '\",';
						jd += '\"n\":\"' + info.push[i].changeRate.v + '\",';
						jd += '\"o\":\"' + info.push[i].volume.v + '\",';
						jd += '\"p\":\"' + info.push[i].nowVolume.v + '\",';
						jd += '\"q\":\"' + info.push[i].turnoverRate.v + '\",';
						jd += '\"r\":\"' + info.push[i].limitUP.v + '\",';
						jd += '\"s\":\"' + info.push[i].limitDown.v + '\",';
						jd += '\"t\":\"' + info.push[i].averageValue.v + '\",';
						jd += '\"u\":\"' + info.push[i].change.v + '\",';
						jd += '\"v\":\"' + info.push[i].amount.v + '\",';
						jd += '\"w\":\"' + info.push[i].volumeRatio.v + '\",';
						jd += '\"x\":\"' + info.push[i].buyPrice.v + '\",';
						jd += '\"y\":\"' + info.push[i].sellPrice.v + '\",';
						jd += '\"z\":\"' + info.push[i].buyVolume.v + '\",';
						jd += '\"a1\":\"' + info.push[i].sellVolume.v + '\",';
						jd += '\"b1\":\"' + info.push[i].totalValue.v + '\",';
						jd += '\"c1\":\"' + info.push[i].flowValue.v + '\",';
						jd += '\"d1\":\"' + info.push[i].netAsset.v + '\",';
						jd += '\"e1\":\"' + info.push[i].pe.v + '\",';
						jd += '\"f1\":\"' + info.push[i].roe.v + '\",';
						jd += '\"g1\":\"' + info.push[i].capitalization.v + '\",';
						jd += '\"h1\":\"' + info.push[i].circulatingShares.v + '\",';
						jd += '\"i1\":\"' + info.push[i].buyPricesTmp.v + '\",';
						jd += '\"j1\":\"' + info.push[i].sellPricesTmp.v + '\",';
						jd += '\"k1\":\"' + info.push[i].buyVolumesTmp.v + '\",';
						jd += '\"l1\":\"' + info.push[i].sellVolumesTmp.v + '\",';
						jd += '\"m1\":\"' + info.push[i].buySingleVolumesTmp.v + '\",';
						jd += '\"n1\":\"' + info.push[i].sellSingleVolumesTmp.v + '\",';
						jd += '\"o1\":\"' + info.push[i].amplitudeRate.v + '\",';
						jd += '\"p1\":\"' + info.push[i].receipts.v + '\",';
						jd += '\"q1\":\"' + info.push[i].tradeTickTmp.v + '\",';
						jd += '\"r1\":\"' + info.push[i].upCount.v + '\",';
						jd += '\"s1\":\"' + info.push[i].sameCount.v + '\",';
						jd += '\"t1\":\"' + info.push[i].downCount.v + '\"}';
					}
					
					jd += ']}';

					$('#quote-compare-table').datagrid('loadData', JSON.parse(jd));
					
					pushIndex = parseInt(info.index);
				}
			}
			else
			{
				/**
				$('#connect-status').html('');
				
				$('#start-btn').removeClass('disabled');
				$('#stop-btn').removeClass('disabled');
				
				$('#start-btn').removeClass('disabled');
				$('#stop-btn').addClass('disabled');
				**/
			}
		}
		else
		{
			$.messager.alert('通知', info.message, 'error');
		}
	});
}

function endEditing()
{
	if(editIndex == undefined)
	{
		return true;
	}
	
	if($('#loc-setting-table').datagrid('validateRow', editIndex))
	{
		var ed = $('#loc-setting-table').datagrid('getEditor', {index:editIndex,field:''});
		//var productname = $(ed.target).combobox('getText');
		//$('#loc-setting-table').datagrid('getRows')[editIndex]['productname'] = productname;
		$('#loc-setting-table').datagrid('endEdit', editIndex);
		editIndex = undefined;
		return true;
	} 
	else 
	{
		return false;
	}
}

function onClickRow(index)
{
	if(editIndex != index)
	{
		if(endEditing())
		{
			$('#loc-setting-table').datagrid('selectRow', index).datagrid('beginEdit', index);
			editIndex = index;
		} 
		else 
		{
			$('#loc-setting-table').datagrid('selectRow', editIndex);
		}
	}
}

/**
$(document).ready(function()
{
	clearInterval(updateConnectStatus);
	updateConnectStatus = setInterval("getConnectStatus()", 1000);
	
	$('#start-btn').on('click', function() 
	{
		$('#start-btn').addClass('disabled');
		$('#stop-btn').removeClass('disabled');
		startService();
 	});

	$('#stop-btn').on('click', function() 
	{
		$('#start-btn').removeClass('disabled');
		$('#stop-btn').addClass('disabled');
		
		stopService();
 	});
});

function isRunning()
{
	send('/d', 'event=t', function callbackComplete(jqXHR, textStatus)
	{}, 
	function callbackError(jqXHR, textStatus, errorThrown)
	{
		$('#message-body').text(errorThrown);
		$('#message-dialog').modal('show');
	}, 
	function callbackSuccess(data, textStatus, jqXHR)
	{
		var info = JSON.parse(data);
		
		if(info.code == '00000')
		{
			if(info.running == 'true')
			{
				$('#stop-btn').removeClass('disabled');
			}
			else
			{
				$('#start-btn').removeClass('disabled');
			}
		}
		else
		{
			$('#message-body').text(info.message);
			$('#message-dialog').modal('show');
		}
	});
}

function startService()
{
	send('/d', 'event=s', function callbackComplete(jqXHR, textStatus)
	{}, 
	function callbackError(jqXHR, textStatus, errorThrown)
	{
		$('#message-body').text(errorThrown);
		$('#message-dialog').modal('show');
	}, 
	function callbackSuccess(data, textStatus, jqXHR)
	{
		var info = JSON.parse(data);
		
		//updateConnectStatus = setInterval("getConnectStatus()", 1000);
		
		//$('#message-body').text(info.message);
		//$('#message-dialog').modal('show');
	});
}

function stopService()
{
	send('/d', 'event=e', function callbackComplete(jqXHR, textStatus)
	{}, 
	function callbackError(jqXHR, textStatus, errorThrown)
	{
		$('#message-body').text(errorThrown);
		$('#message-dialog').modal('show');
	}, 
	function callbackSuccess(data, textStatus, jqXHR)
	{
		var info = JSON.parse(data);
		
		$('#connect-status').html('');
		//$('#message-body').text(info.message);
		//$('#message-dialog').modal('show');
	});
}

function getConnectStatus()
{
	send('/d', 'event=g&src=' + pushIndex, function callbackComplete(jqXHR, textStatus)
	{}, 
	function callbackError(jqXHR, textStatus, errorThrown)
	{
		$('#message-body').text(errorThrown);
		$('#message-dialog').modal('show');
	}, 
	function callbackSuccess(data, textStatus, jqXHR)
	{
		//console.log(data);
		var info = JSON.parse(data);
		
		if(info.code == '00000')
		{
			if(info.running == 'true')
			{
				$('#start-btn').removeClass('disabled');
				$('#stop-btn').removeClass('disabled');
				
				$('#start-btn').addClass('disabled');
				$('#stop-btn').removeClass('disabled');
				
				if(info.host.length > 0)
				{
					var s = '';
					
					for(i = 0 ; i < info.host.length ; i++)
					{
						s += '(' +　info.host[i].ip + '_' + (info.host[1].status == '0' ? "连线中" : "<font style=\"color:#990000;\">断线中</font>") + '),';
					}

					s += '数据比对中.....';
					
					$('#w-btn').text('发送报文数量:' + info.w);
					$('#r-btn').text('回应报文数量:' + info.r);
					$('#connect-status').html(s);
				}
				
				if(info.push.length > 0)	
				{
					for(i = 0 ; i < info.push.length ; i++)
					{
						$('#list-tbody').append('<tr>');
						$('#list-tbody').append('<td>' + info.push[i].host + '</td>');
						$('#list-tbody').append('<td>' + info.push[i].responseTime + '</td>');
						
						$('#list-tbody').append('<td' + (info.push[i].status.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].status.v + '</td>');
						
						$('#list-tbody').append('<td>' + info.push[i].id + '</td>');
						$('#list-tbody').append('<td>' + info.push[i].name + '</td>');
						
						$('#list-tbody').append('<td' + (info.push[i].datetime.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].datetime.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].market.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].market.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].subtype.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].subtype.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].lastPrice.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].lastPrice.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].highPrice.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].highPrice.v + '</td>');
						
						$('#list-tbody').append('<td' + (info.push[i].lowPrice.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].lowPrice.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].openPrice.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].openPrice.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].preClosePrice.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].preClosePrice.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].changeRate.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].changeRate.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].volume.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].volume.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].nowVolume.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].nowVolume.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].turnoverRate.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].turnoverRate.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].limitUP.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].limitUP.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].limitDown.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].limitDown.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].averageValue.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].averageValue.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].change.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].change.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].amount.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].amount.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].volumeRatio.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].volumeRatio.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].buyPrice.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].buyPrice.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].sellPrice.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].sellPrice.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].buyVolume.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].buyVolume.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].sellVolume.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].sellVolume.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].totalValue.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].totalValue.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].flowValue.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].flowValue.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].netAsset.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].netAsset.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].pe.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].pe.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].roe.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].roe.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].capitalization.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].capitalization.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].circulatingShares.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].circulatingShares.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].buyPricesTmp.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].buyPricesTmp.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].sellPricesTmp.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].sellPricesTmp.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].buyVolumesTmp.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].buyVolumesTmp.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].sellVolumesTmp.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].sellVolumesTmp.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].buySingleVolumesTmp.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].buySingleVolumesTmp.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].sellSingleVolumesTmp.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].sellSingleVolumesTmp.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].amplitudeRate.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].amplitudeRate.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].receipts.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].receipts.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].tradeTickTmp.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].tradeTickTmp.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].upCount.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].upCount.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].sameCount.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].sameCount.v + '</td>');
						$('#list-tbody').append('<td' + (info.push[i].downCount.d == 'Y' ? ' style=\"color: #ff0000;\"' : '') + '>' + info.push[i].downCount.v + '</td>');
						$('#list-tbody').append('</tr>');
					}
					
					pushIndex = parseInt(info.index);
				}
			}
			else
			{
				$('#connect-status').html('');
				
				$('#start-btn').removeClass('disabled');
				$('#stop-btn').removeClass('disabled');
				
				$('#start-btn').removeClass('disabled');
				$('#stop-btn').addClass('disabled');
			}
		}
		else
		{
			$('#message-body').text(info.message);
			$('#message-dialog').modal('show');
		}
	});
}
**/
</script>